<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Elasticsearch 核心架构解析 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.8;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .section-title {
            position: relative;
            padding-left: 2rem;
        }
        .section-title:before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 0.5rem;
            height: 1.5rem;
            background: #4f46e5;
            border-radius: 0.25rem;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
        }
        .feature-icon {
            width: 3.5rem;
            height: 3.5rem;
            background: rgba(79, 70, 229, 0.1);
        }
        .concept-card {
            border-left: 4px solid #4f46e5;
        }
        .mermaid-container {
            background: #f8fafc;
            border-radius: 0.5rem;
            padding: 1.5rem;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <header class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">Elasticsearch <br>核心架构解析</h1>
                    <p class="text-xl opacity-90 mb-8">深入探索分布式搜索与分析引擎的内部结构</p>
                    <div class="flex items-center space-x-4">
                        <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full flex items-center">
                            <i class="fas fa-bolt mr-2"></i> 高性能
                        </span>
                        <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full flex items-center">
                            <i class="fas fa-expand-arrows-alt mr-2"></i> 分布式
                        </span>
                        <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full flex items-center">
                            <i class="fas fa-search mr-2"></i> 全文检索
                        </span>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="relative w-full max-w-md">
                        <div class="absolute inset-0 bg-purple-500 rounded-2xl transform rotate-6"></div>
                        <div class="relative bg-white text-gray-800 p-6 rounded-2xl shadow-xl">
                            <div class="flex items-center mb-4">
                                <div class="w-3 h-3 rounded-full bg-red-500 mr-2"></div>
                                <div class="w-3 h-3 rounded-full bg-yellow-500 mr-2"></div>
                                <div class="w-3 h-3 rounded-full bg-green-500"></div>
                            </div>
                            <pre class="text-sm font-mono bg-gray-100 p-4 rounded-lg overflow-x-auto">
{
  "name": "Elasticsearch",
  "type": "search-engine",
  "architecture": "distributed",
  "features": [
    "full-text-search",
    "real-time-analytics",
    "horizontal-scaling"
  ],
  "version": "8.x"
}</pre>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-16">
        <!-- Introduction -->
        <section class="mb-20">
            <div class="bg-white rounded-xl shadow-md p-8">
                <h2 class="text-2xl font-bold mb-6 text-gray-800">Elasticsearch 概述</h2>
                <p class="text-gray-700 mb-6">
                    Elasticsearch (ES) 是一个基于 Lucene 的分布式搜索和分析引擎，能够在海量数据中实现近乎实时的搜索能力。
                    它不仅是一个全文搜索引擎，还提供了强大的数据分析功能，广泛应用于日志分析、应用搜索、安全分析等领域。
                </p>
                <div class="grid md:grid-cols-3 gap-6 mt-8">
                    <div class="bg-gray-50 p-6 rounded-lg border border-gray-200 flex items-start">
                        <div class="feature-icon rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-server text-purple-600 text-xl"></i>
                        </div>
                        <div>
                            <h3 class="font-bold text-lg mb-2">分布式架构</h3>
                            <p class="text-gray-600">自动分片和复制，实现水平扩展和高可用性</p>
                        </div>
                    </div>
                    <div class="bg-gray-50 p-6 rounded-lg border border-gray-200 flex items-start">
                        <div class="feature-icon rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-tachometer-alt text-purple-600 text-xl"></i>
                        </div>
                        <div>
                            <h3 class="font-bold text-lg mb-2">近实时搜索</h3>
                            <p class="text-gray-600">数据几乎立即可搜索，延迟通常在1秒内</p>
                        </div>
                    </div>
                    <div class="bg-gray-50 p-6 rounded-lg border border-gray-200 flex items-start">
                        <div class="feature-icon rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-chart-pie text-purple-600 text-xl"></i>
                        </div>
                        <div>
                            <h3 class="font-bold text-lg mb-2">多维分析</h3>
                            <p class="text-gray-600">强大的聚合功能，支持复杂的数据分析</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Core Components -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 section-title">核心组件</h2>
            
            <!-- Architecture Diagram -->
            <div class="mermaid-container mb-12">
                <div class="mermaid">
                    graph TD
                    A[Elasticsearch Cluster] --> B[Node 1]
                    A --> C[Node 2]
                    A --> D[Node 3]
                    B --> E[Index A]
                    B --> F[Index B]
                    C --> E
                    C --> F
                    D --> E
                    D --> F
                    E --> G[Shard 1]
                    E --> H[Shard 2]
                    F --> I[Shard 1]
                    F --> J[Shard 2]
                    G --> K[Primary]
                    H --> L[Replica]
                    I --> M[Primary]
                    J --> N[Replica]
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <!-- Node and Cluster -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-purple-100 text-purple-600 flex items-center justify-center mr-4">
                                <i class="fas fa-network-wired"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">1. 节点 (Node) 和集群 (Cluster)</h3>
                        </div>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex">
                                <span class="text-purple-600 mr-2">•</span>
                                <span><strong>节点</strong>：ES实例称为节点，节点可以独立运行，也可以组成集群。每个节点都有一个唯一的ID。</span>
                            </li>
                            <li class="flex">
                                <span class="text-purple-600 mr-2">•</span>
                                <span><strong>集群</strong>：多个节点组成的集合，提供高可用性和分布式搜索能力。集群通过一个名字标识，所有节点都需要加入同一个集群。</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <!-- Index -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-purple-100 text-purple-600 flex items-center justify-center mr-4">
                                <i class="fas fa-database"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">2. 索引 (Index)</h3>
                        </div>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex">
                                <span class="text-purple-600 mr-2">•</span>
                                <span>索引是ES存储和管理文档的结构，类似于关系型数据库中的数据库。每个索引都有一个名称，并包含多个文档。</span>
                            </li>
                            <li class="flex">
                                <span class="text-purple-600 mr-2">•</span>
                                <span>索引中的文档以JSON格式存储，支持多种数据类型。</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <!-- Shard -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-purple-100 text-purple-600 flex items-center justify-center mr-4">
                                <i class="fas fa-puzzle-piece"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">3. 分片 (Shard)</h3>
                        </div>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex">
                                <span class="text-purple-600 mr-2">•</span>
                                <span>每个索引被划分为多个分片。分片是索引的基本单位，负责存储和检索文档。</span>
                            </li>
                            <li class="flex">
                                <span class="text-purple-600 mr-2">•</span>
                                <span>分片有主分片（primary shard）和副本分片（replica shard）。主分片处理写入操作，副本分片用于高可用性和负载均衡。</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <!-- Document -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-purple-100 text-purple-600 flex items-center justify-center mr-4">
                                <i class="fas fa-file-alt"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">4. 文档 (Document)</h3>
                        </div>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex">
                                <span class="text-purple-600 mr-2">•</span>
                                <span>文档是ES中的基本信息单位，包含键值对。每个文档在索引中具有唯一的ID。</span>
                            </li>
                            <li class="flex">
                                <span class="text-purple-600 mr-2">•</span>
                                <span>文档的结构可以灵活定义，允许动态添加字段。</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <!-- Mapping -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-purple-100 text-purple-600 flex items-center justify-center mr-4">
                                <i class="fas fa-project-diagram"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">5. 映射 (Mapping)</h3>
                        </div>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex">
                                <span class="text-purple-600 mr-2">•</span>
                                <span>映射定义了索引中文档的结构和数据类型，包括字段类型、分词器、索引方式等。</span>
                            </li>
                            <li class="flex">
                                <span class="text-purple-600 mr-2">•</span>
                                <span>映射可以在索引创建时定义，也可以在后续操作中动态调整。</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <!-- Query and Aggregation -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-purple-100 text-purple-600 flex items-center justify-center mr-4">
                                <i class="fas fa-search"></i>
                            </div>
                            <h3 class="text-xl font-bold text-gray-800">6. 查询 (Query) 和聚合 (Aggregation)</h3>
                        </div>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex">
                                <span class="text-purple-600 mr-2">•</span>
                                <span>ES支持强大的查询DSL（Domain Specific Language），允许用户进行复杂的搜索操作。</span>
                            </li>
                            <li class="flex">
                                <span class="text-purple-600 mr-2">•</span>
                                <span>聚合功能允许对文档进行分析和统计，支持多种聚合类型，如计数、求和、最大值等。</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Advanced Concepts -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 section-title">高级概念</h2>
            
            <div class="grid md:grid-cols-3 gap-6">
                <!-- Cluster State -->
                <div class="bg-white rounded-lg shadow-sm p-6 concept-card">
                    <h3 class="font-bold text-lg mb-3">7. 集群状态 (Cluster State)</h3>
                    <p class="text-gray-600">集群状态是集群的元数据，描述了节点、索引、分片等信息。集群状态在节点间共享，用于协调和管理。</p>
                </div>
                
                <!-- Inverted Index -->
                <div class="bg-white rounded-lg shadow-sm p-6 concept-card">
                    <h3 class="font-bold text-lg mb-3">8. 反向索引 (Inverted Index)</h3>
                    <p class="text-gray-600">ES基于反向索引实现快速搜索。反向索引将文档的内容转化为词项及其在文档中的位置，极大提升查询效率。</p>
                </div>
                
                <!-- Node Communication -->
                <div class="bg-white rounded-lg shadow-sm p-6 concept-card">
                    <h3 class="font-bold text-lg mb-3">9. 节点通信与协调</h3>
                    <p class="text-gray-600">节点之间通过Zen Discovery进行集群管理和成员发现。选举主节点并协调集群状态更新。</p>
                </div>
                
                <!-- Plugins -->
                <div class="bg-white rounded-lg shadow-sm p-6 concept-card">
                    <h3 class="font-bold text-lg mb-3">10. 插件 (Plugins)</h3>
                    <p class="text-gray-600">ES支持插件架构，允许扩展功能和定制化操作。常用插件包括分析器、监控、备份等。</p>
                </div>
            </div>
        </section>

        <!-- Use Cases -->
        <section class="mb-20">
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="p-8">
                    <h2 class="text-2xl font-bold mb-6 text-gray-800">Elasticsearch 典型应用场景</h2>
                    <div class="grid md:grid-cols-3 gap-6">
                        <div class="border border-gray-200 rounded-lg p-6 hover:border-purple-500 transition-colors">
                            <div class="text-purple-600 text-3xl mb-4">
                                <i class="fas fa-search"></i>
                            </div>
                            <h3 class="font-bold text-lg mb-2">全文搜索</h3>
                            <p class="text-gray-600">为应用程序提供强大的全文搜索功能，支持复杂查询和高亮显示。</p>
                        </div>
                        <div class="border border-gray-200 rounded-lg p-6 hover:border-purple-500 transition-colors">
                            <div class="text-purple-600 text-3xl mb-4">
                                <i class="fas fa-chart-line"></i>
                            </div>
                            <h3 class="font-bold text-lg mb-2">日志分析</h3>
                            <p class="text-gray-600">结合Kibana，实现日志收集、存储、分析和可视化的一体化解决方案。</p>
                        </div>
                        <div class="border border-gray-200 rounded-lg p-6 hover:border-purple-500 transition-colors">
                            <div class="text-purple-600 text-3xl mb-4">
                                <i class="fas fa-shield-alt"></i>
                            </div>
                            <h3 class="font-bold text-lg mb-2">安全分析</h3>
                            <p class="text-gray-600">通过分析安全事件日志，识别潜在的安全威胁和异常行为。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-400 hover:text-white transition-colors">
                        <i class="fas fa-link mr-2"></i> http://www.yuque.com/jtostring
                    </a>
                </div>
                <div class="flex space-x-4">
                    <a href="#" class="w-10 h-10 rounded-full bg-gray-700 hover:bg-purple-600 flex items-center justify-center transition-colors">
                        <i class="fab fa-github"></i>
                    </a>
                    <a href="#" class="w-10 h-10 rounded-full bg-gray-700 hover:bg-blue-500 flex items-center justify-center transition-colors">
                        <i class="fab fa-twitter"></i>
                    </a>
                    <a href="#" class="w-10 h-10 rounded-full bg-gray-700 hover:bg-blue-700 flex items-center justify-center transition-colors">
                        <i class="fab fa-linkedin-in"></i>
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            fontFamily: 'inherit',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true
            }
        });
    </script>
</body>
</html>